<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.arquitecturajava.DataBaseHelper" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="css/formato.css" />
	<script type="text/javascript" src="js/validacion.js" ></script>
</head>
<body>
	<form action="InsertarLibro.jsp" onsubmit="return validacion();">
		<fieldset>
			<legend>Formulario alta libro</legend>
			<p><label for="isbn">ISBN:</label>
			<input id="isbn" type="text" name="isbn"/>
			</p>
			<p>
			<label for="titulo">Titulo:</label>
			<input id="titulo" type="text" name="titulo"/>
			</p>
			<p>
			<label for="categoria">Categoria:</label>
			<select name="categoria" id="categoria">
			<option value="seleccionar">seleccionar</option>
			<%
			ResultSet rs=null;	
			
			try {
				String consultaSQL = "select distinct(categoria) from libros";
				DataBaseHelper db = new DataBaseHelper();
				rs = db.seleccionarRegistros(consultaSQL);
				while (rs.next()) {%> 
					<option value="<%=rs.getString("categoria")  %>">
						<%=rs.getString("categoria") %>
					</option>
				 <% 
					
				}
				
			} catch (SQLException e) {
				System.out.println("Error en la consulta SQL :" + e.getMessage());
			} finally {
				if (rs != null) {
					try {rs.close();} catch (SQLException e)
					{System.out.println("Error cerrando el resultset" + e.getMessage());}
				}
			}
			
			%>
			
			</select>
			<p>
			<input type="submit" value="Insertar" />
			</p>
		</fieldset>
	</form>
</body>
</html>